﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MoneyCalc
{
    public partial class MoneyCalc : Form
    {
        public MoneyCalc()
        {
            InitializeComponent();

            dataGridView1.RowCount = 0;
            dataGridView1.Rows.Add("养老保险金");
            dataGridView1.Rows.Add("医疗保险金");
            dataGridView1.Rows.Add("失业保险金");
            dataGridView1.Rows.Add("住房保险金");
            dataGridView1.Rows.Add("工伤保险金");
            dataGridView1.Rows.Add("生育保险金");
            dataGridView1.Rows.Add("缴费总合计");

            radioButton1.Checked = false;   // true;
            radioButton3.Checked = true;
            radioButton4.Checked = true;
            radioButton7.Checked = true;

            radioButton2.Checked = true;    // false;
            radioButton5.Checked = false;
            radioButton6.Checked = false;
            radioButton8.Checked = false;

            dataGridView2.RowCount = 0;
            dataGridView2.Rows.Add("养老保险", 22, 8, 30);
            dataGridView2.Rows.Add("医疗保险", 12, 2, 14);
            dataGridView2.Rows.Add("失业保险", 2, 1, 3);
            dataGridView2.Rows.Add("住房公积", 7, 7, 14);
            dataGridView2.Rows.Add("工伤保险", 0.5, 0, 0.5);
            dataGridView2.Rows.Add("生育保险", 0.5, 0, 0.5);
            dataGridView2.Rows.Add("纵向合计", 44, 18);

            dataGridView3.RowCount = 0;
            dataGridView3.Rows.Add(1, 0, 1500, 3, 0);
            dataGridView3.Rows.Add(2, 1500, 4500, 10, 105);
            dataGridView3.Rows.Add(3, 4500, 9000, 20, 555);
            dataGridView3.Rows.Add(4, 9000, 35000, 25, 1005);
            dataGridView3.Rows.Add(5, 35000, 55000, 30, 2725);
            dataGridView3.Rows.Add(6, 55000, 80000, 35, 5505);
            dataGridView3.Rows.Add(7, 80000, 100000, 45, 13505);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 计算税后
            if (null == textBox1.Text)
            {
                return;
            }
            int salary = 50000;
            salary = int.Parse(textBox1.Text);
            int safe = 0;
            textBox2.Text = safe.ToString();
            textBox3.Text = safe.ToString();

            for (int i = 0; i < 7; i++)
            {
                for (int j = 1; j < 3; j++)
                {
                    dataGridView1[j, i].Value = safe * double.Parse(dataGridView2[j, i].Value.ToString()) / 100;
                }
            }

            int beftax = 50000;
            beftax = salary - int.Parse(dataGridView1[2, 6].Value.ToString());
            textBox4.Text = beftax.ToString();

            // calculate tax
            int edge = 0;
            int taxori = 3500;
            taxori = int.Parse(textBox11.Text);
            int k = 0;
            for (k = 0; k < dataGridView3.RowCount; k++)
            {                
                edge = int.Parse(dataGridView3[2, k].Value.ToString()) + 3500;
                if (beftax < edge)
                {
                    break;
                }
            }
            int tax = 0;
            tax = (beftax - taxori) * int.Parse(dataGridView3[3, k].Value.ToString()) / 100 - int.Parse(dataGridView3[4, k].Value.ToString());
            textBox5.Text = tax.ToString();

            int money = 50000;
            money = beftax - tax;
            textBox6.Text = money.ToString();
        }
    }
}
